from sqlalchemy import select
from app.api.admin.model.coupon.coupon import CouponCateModel
from app.api.admin.schema.coupon.coupon_cate import CouponCateInSchema, CouponCateOutSchema
from app.dependencies.database import db


class CouponCateService:

    async def list(self):
        records = await db.fetch_all(select(CouponCateModel))
        if not records:
            return []
        return [CouponCateOutSchema.model_validate(record, from_attributes=True) for record in records]

    @classmethod
    async def instance(cls) -> "CouponCateService":
        return cls()
